#version 330 core
layout(location = 0) in float angle;
layout(location = 1) in float type;

uniform mat4 projection;
uniform vec2 center;
uniform float currentStartRadius;
uniform float currentEndRadius;
uniform vec4 color;
uniform vec2 borderAngleOuter;
uniform vec2 borderAngleInner;
uniform vec2 angleRange;
uniform float borderRadius;

out vec4 fragColor;
out float radius;

void main() {
    radius = (type > 0.5) ? currentEndRadius : currentStartRadius;
    float additionSign = (type > 0.5) ? -1 : 1;
    radius = max(radius, 0.0);
    vec2 borderAngle = (type > 0.5) ? borderAngleOuter : borderAngleInner;
    if (angle > borderAngle.y) {
        float maxAngleDiff = angleRange.y - borderAngle.y;
        float normAngle = angle - borderAngle.y;
        radius += (borderRadius - borderRadius * sqrt(1 - (normAngle * normAngle) / (maxAngleDiff * maxAngleDiff))) * additionSign;
    }
    else if(angle < borderAngle.x) {
        float maxAngleDiff = borderAngle.x - angleRange.x;
        float normAngle = borderAngle.x - angle;
        radius += (borderRadius - borderRadius * sqrt(1 - (normAngle * normAngle) / (maxAngleDiff * maxAngleDiff))) * additionSign;
    }
    vec2 pos = center + radius * vec2(cos(angle), -sin(angle));
    gl_Position = projection * vec4(pos, 0.0, 1.0);
    fragColor = color;
}